nums = [2,7,11,15]
target = 9

//暴力
var twoSum = function(nums, target) {
  for (let i = 0; i < nums.length; i ++) {
      for (let j = i + 1; j < nums.length; j ++) {
          if (nums[i] + nums[j] === target) return [i, j]
      }
  }
};

//哈希
var twoSum = function(nums, target) {
  const obj = {}
  for (let i = 0; i < nums.length; i++) {
    const t = target - nums[i]
    if (obj[t] !== undefined) return [obj[t], i]
    obj[nums[i]] = i
  }
};

console.log(twoSum(nums, target))
